/*
 * Copyright (C) 2010 Yellow_Panther
 * 
 * yanick.saugy@gmail.com - http://www.help-info.ch
 *
 *     This file is part of BTRemote.
 *
 *    BTRemote is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    BTRemote is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with BTRemote.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package ch.yp.android.btremote;

import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;

/**
 * 
 * @author panther
 * @version 0.1
 */
public class BTRemote extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		Button button = (Button) findViewById(R.id.btnConnect);
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent intent = new Intent("ch.yp.android.btremote.Remote");
				startActivity(intent);
			}
		});

		button = (Button) findViewById(R.id.btnAbout);
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				AlertDialog.Builder builder;
				AlertDialog alertDialog;

				Context mContext = BTRemote.this;
				LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
				View layout = inflater.inflate(R.layout.about,
				                               (ViewGroup) findViewById(R.id.lytAbout));

				TextView text = (TextView) layout.findViewById(R.id.txtAbout);
				text.setText(getString(R.string.app_name)+" v"+getString(R.string.version)+getString(R.string.about_dialog));
				ImageView image = (ImageView) layout.findViewById(R.id.imgAbout);
				image.setImageResource(R.drawable.icon);

				builder = new AlertDialog.Builder(mContext);
				builder.setView(layout);
				builder.setCancelable(true).setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
				alertDialog = builder.create();	
				alertDialog.show();
			}
		}); 
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()) {
		case R.id.mnuQuit:
			finish();
        	return true;
        }
		return false;
	}

	/**
	 * 
	 * @param context
	 * @param text
	 */
	public static void showDialog(Context context, int textID) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(textID).setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		});
		AlertDialog alert = builder.create();
		alert.show();
	}
	
	/**
	 * 
	 * @param context
	 * @param text
	 */
	public static void tooltip(Context context, String text){
		Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
	}

}
